package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysDictItem;
import com.pine.dao.pineframework.mapper.SysDictItemMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysDictItemBo;
import com.pine.manager.pineframework.convertors.SysDictItemConvertor;
import com.pine.manager.pineframework.query.SysDictItemQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 字典数据表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysDictItemManager extends BaseManager<SysDictItemMapper, SysDictItem, Long, SysDictItemBo, SysDictItemQuery, SysDictItemConvertor> {

    @Resource
    private SysDictItemConvertor sysDictItemConvertor;

    @Override
    public LambdaQueryWrapper<SysDictItem> encapsulateQueryWrapper(SysDictItemQuery query) {
        LambdaQueryWrapper<SysDictItem> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getDictId()), SysDictItem::getDictId, query.getDictId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysDictItem::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getValue()), SysDictItem::getValue, query.getValue());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysDictItem::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getSort()), SysDictItem::getSort, query.getSort());
        queryWrapper.like(ObjectUtils.isNotEmpty(query.getRemark()), SysDictItem::getRemark, query.getRemark());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysDictItem::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysDictItem::getUpdateTime, query.getUpdateTimeEnd());

        // 排序
        queryWrapper.orderByAsc(SysDictItem::getSort);
        return queryWrapper;
    }
}
